//
//  SISSUploadEntrustContractViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/6/28.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSUploadContractsViewController.h"
#import "SISSDatePickerView.h"
#import "SISSUploadSuccessViewController.h"

@interface SISSUploadContractsViewController ()<SISSChooseViewDelegate,SISSDatePickerViewDelegate>

// 保存
@property (weak, nonatomic) UIButton *confirmButton;


@end

@implementation SISSUploadContractsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}


#pragma mark - SISSChooseViewDelegate
- (void)clickChooseActionWithChooseView:(SISSChooseView *)chooseView {
    [self.view endEditing:YES];
    SISSDatePickerView *datePickerView = [[SISSDatePickerView alloc] initWithType:UIDatePickerModeDate title:@"日期"];
    if (self.contractDateChooseView.rightStr.length > 0) {
        [datePickerView setNowTime:[NSDate yyr_stringToDate:self.contractDateChooseView.rightStr withDateFormat:@"yyyy-MM-dd"]];
    } else {
       [datePickerView setNowTime:[NSDate date]];
    }
//    [datePickerView setMaximumDate:[NSDate date]];
    datePickerView.delegate = self;
}

#pragma mark - SISSDatePickerViewDelegate
- (void)determine:(SISSDatePickerView *)choose date:(NSDate *)date {
    
    NSString *timeStr = [choose stringFromDate:date];
    self.contractDateChooseView.rightStr = timeStr;
    NSLog(@"determine  %@",timeStr);
   
}

- (void)changeTime:(SISSDatePickerView *)choose date:(NSDate *)date {
    
    NSString *timeStr = [choose stringFromDate:date];
    NSLog(@"changeTime  %@",timeStr);
}

// 确定按钮点击事件
- (void)confirmButtonClickAction {
    [self.view endEditing:YES];
    
}

- (void)pushToSuccessViewWithPopBackClassType:(SISSProgressPopBackClassType)popBackClassType {
    SISSUploadSuccessViewController *vc = [[SISSUploadSuccessViewController alloc] init];
    vc.popBackClassType = popBackClassType;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.containerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    SISSLabelTextFieldView *contractNoView = [[SISSLabelTextFieldView alloc] init];
    contractNoView.leftStr = @"*合同编号";
    contractNoView.rightPlaceStr = @"请输入合同编号";
    contractNoView.isShowBottomLine = YES;
    [self.containerView addSubview:contractNoView];
    self.contractNoView = contractNoView;
    
    if (!self.isHiddenDateChooseView) {
        SISSChooseView *contractDateChooseView = [[SISSChooseView alloc] init];
        contractDateChooseView.leftStr = @"*合同截止日期";
        contractDateChooseView.rightPlaceStr = @"请选择合同截止日期";
        contractDateChooseView.delegate = self;
        contractDateChooseView.isShowBottomLine = YES;
        contractDateChooseView.hidden = self.isHiddenDateChooseView;
        [self.containerView addSubview:contractDateChooseView];
        self.contractDateChooseView = contractDateChooseView;
    }
    
    SISSLabelTextFieldView *remarkView = [[SISSLabelTextFieldView alloc] init];
    remarkView.leftStr = @"备注";
    remarkView.rightPlaceStr = @"请输入备注";
    remarkView.isShowBottomLine = YES;
    [self.containerView addSubview:remarkView];
    self.remarkView = remarkView;
    
    SISSUploadImageView *uploadImageView = [[SISSUploadImageView alloc] init];
    [self.containerView addSubview:uploadImageView];
    self.uploadImageView = uploadImageView;
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmButton setTitle:@"保存" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:MAIN_COLOR];
    [confirmButton addTarget:self action:@selector(confirmButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    confirmButton.layer.cornerRadius = 4;
    confirmButton.layer.masksToBounds = YES;
    [self.containerView addSubview:confirmButton];
    self.confirmButton = confirmButton;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGSize buttonSize = CGSizeMake(SCREEN_WIDTH * 0.8, 54);
    [self.contractNoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.containerView).offset(globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5.5 * globelMargin);
    }];
    
    if (!self.isHiddenDateChooseView) {
        [self.contractDateChooseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contractNoView.mas_bottom);
            make.left.right.equalTo(weakSelf.containerView);
            make.height.mas_equalTo(5.5 * globelMargin);
        }];
    }
    
    [self.remarkView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (weakSelf.isHiddenDateChooseView) {
            make.top.equalTo(weakSelf.contractNoView.mas_bottom);
        } else {
            make.top.equalTo(weakSelf.contractDateChooseView.mas_bottom);
        }
        make.left.right.equalTo(weakSelf.containerView);
        make.height.mas_equalTo(5.5 * globelMargin);
    }];

    [self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.remarkView.mas_bottom).offset(5.5 * globelMargin);
        make.left.right.equalTo(weakSelf.containerView);
    }];
    
    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.uploadImageView.mas_bottom).offset(6 * globelMargin);
        make.centerX.equalTo(weakSelf.containerView.mas_centerX);
        make.size.mas_equalTo(buttonSize);
        make.bottom.equalTo(weakSelf.containerView).offset(-2 * globelMargin);
    }];
    
}

@end
